package com.link4a.doms.web.tag;

import com.link4a.doms.web.SessionContext;
import com.link4a.doms.web.UserWrapper;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

public class PermissionValid extends BodyTagSupport {
	private static final long serialVersionUID = -7916441699943106858L;
	
	protected String permission;

	public int doStartTag() throws JspException {
		return doStartTag(false);
	}
	
	protected int doStartTag(boolean reverse) throws JspException {
		UserWrapper userInfo = (UserWrapper)pageContext.getSession().getAttribute(SessionContext.SESSION_KEY_LOGIN_USER);
		if (userInfo != null && userInfo.getPermissions().contains(permission)) {
			return reverse ? Tag.SKIP_BODY : Tag.EVAL_BODY_INCLUDE;
		}
		return reverse ? Tag.EVAL_BODY_INCLUDE : Tag.SKIP_BODY;
	}

	
	public String getPermission() {
		return permission;
	}

	
	public void setPermission(String permission) {
		this.permission = permission;
	}
	
}